//app.js
import config from "./utils/config.js";

App({
	onLaunch: function () {
		if (!wx.cloud) {
			console.error('请使用 2.2.3 或以上的基础库以使用云能力')
		} else {
			wx.cloud.init({
				env: config.env,
				traceUser: true,
			})
		}
		//获取用户信息
		wx.getSetting({
			success: res => {
				if (res.authSetting['scope.userInfo']) {
					wx.getUserInfo({
						success: res => {
							this.globalData.userInfo = res.userInfo;
							if (this.getUserInfo) {
								this.getUserInfo(res)
							}
						}
					})
				}
			}
		})

		//获取openid
		wx.cloud.callFunction({
			name: 'login',
			complete: res => {
				if (res.result) {
					wx.setStorageSync("openid", res.result.openid)
				}

			}
		})

	},
	globalData: {
		userInfo: null,
		audioContext: wx.getBackgroundAudioManager(),
		appName: config.appName,
		timer:null,		//定时关闭时间 单位秒
	}
})